﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SiteAgle.Models
{
    public partial class Projeto
    {
        public IList<Tarefa> ListaTarefas()
        {
            IList<Tarefa> lista = new List<Tarefa>();
            Sprint sprint = this.Sprints.Where(w => w.Inicio <= DateTime.Now && w.Fim >= DateTime.Now).FirstOrDefault();
            if (sprint != null)
                lista = sprint.Tarefas.OrderBy(t => t.StatusTarefas.Id).ToList();
            return lista;
        }

        public IEnumerable<SelectListItem> UsersGroup()
        {
            List<SelectListItem> listItem = new List<SelectListItem>();
            listItem.Add(new SelectListItem() { Text = "", Value = "0" });
            foreach (Usuario user in this.GrupoTrabalho.Usuarios)
            {
                listItem.Add(new SelectListItem() { Text = user.Nome, Value = user.Id.ToString() });
            }
            return listItem;
        }
        public decimal storyPoint(int value)
        {
            int totalValue = (from tarefas in DataAccessSingleton.Entities.Tarefa
                              where tarefas.Sprint.Projeto.Id == this.Id && tarefas.StatusTarefas.Id == value
                              select tarefas).Count();
            int total = (from tarefas in DataAccessSingleton.Entities.Tarefa
                         where tarefas.Sprint.Projeto.Id == this.Id
                         select tarefas).Count();

            decimal percentual = 0;
            if (total != 0)
            {
                percentual = (totalValue * 100) / total;
            }
            return percentual;

        }
        public decimal storyPointSprint(int value)
        {
            Sprint sprint = this.Sprints.Where(w => w.Inicio <= DateTime.Now && w.Fim >= DateTime.Now).FirstOrDefault();
            if (sprint == null)
            {
                return 0; 
            }
            int totalValue = (from tarefas in DataAccessSingleton.Entities.Tarefa
                              where tarefas.Sprint.Id == sprint.Id && tarefas.StatusTarefas.Id == value
                              select tarefas).Count();
            int total = (from tarefas in DataAccessSingleton.Entities.Tarefa
                         where tarefas.Sprint.Id == sprint.Id
                         select tarefas).Count();

            decimal percentual = 0;
            if (total != 0)
            {
                percentual = (totalValue * 100) / total;
            }
            return percentual;

        }
    }
}